<?php
	$seitcm_student_id = isset($_GET['id']) ? $_GET['id'] : 0;
	if(!seitcm_check_exist_student_id($seitcm_student_id)) wp_die("Invalind student id");
	//$seitcm_student_data = seitcm_get_single_student($seitcm_student_id);
	//print_r($seitcm_student_data);
	$seitcm_class_list = seitcm_get_class_list_learned($seitcm_student_id);
	$chartdata = array();
	?>
	<div id="seitcm_wrapper_ms">
		<div id="seitcm_header">
			<div id="seitcm_head_logo">
				<h1><?php _e('Sunshine Education','SEITCM') ?></h1>
				<h2><?php echo __('Study result for student ','SEITCM') . get_user_meta($seitcm_student_id,'first_name',true) . ' ' . get_user_meta($seitcm_student_id,'last_name',true)?></h2>
			</div>
			<div id="seitcm_head_menu">
				
			</div>
			<div class="seitcm_clearfload">
			</div>
		</div>
		<div class="seitcm_bigwidget_block">
			<div class="seitcm_bigwidget_block_inner">
				<table class="seitcm_grid"><tbody>
					<tr>
						<th rowspan="2"><?php _e('NO','SEITCM')?></th>
						<th rowspan="2"><?php _e('Class','SEITCM')?></th>
						<th rowspan="2"><?php _e('Start time','SEITCM')?></th>
						<th rowspan="2"><?php _e('Finish time','SEITCM')?></th>
						<th colspan="3" style=""><?php _e('Study results','SEITCM')?></th>
					</tr>
					<tr>
						<th><?php _e('Periodic','SEITCM')?></th>
						<th><?php _e('Exam','SEITCM')?></th>
						<th><?php _e('Result','SEITCM')?></th>
						
					</tr>
					<?php
						$i=0;
						foreach ($seitcm_class_list as $seitcm_row)
						{
							?>
							<tr>
								<td><?php echo ++$i?></td>
								<td><?php echo $seitcm_row->codename . '.' . $seitcm_row->classcode?></td>
								<td><?php echo seitcm_create_date_from_mysql($seitcm_row->startdate)?></td>
								<td><?php echo seitcm_create_date_from_mysql(seitcm_get_class_finish_time($seitcm_row->id))?></td>
								<td>
									<?php 
									//Periodic Reviews
									$total_periodic = 0;
									$detail = '<div style="height:250px; overflow-y:scroll; border: 1px #cfcfcf solid;border-radius: 5px 5px 0px 0px;margin-top: 5px;"><table class="seitcm_grid">
													<tr>
														<th>'.__('Score','SEITCM').'</th>
														<th>'.__('Skill','SEITCM').'</th>
														<th>'.__('Time','SEITCM').'</th>
													</tr>';
									$scorearr = seitcm_get_list_periodicreviews($seitcm_row->id, $seitcm_student_id);
									foreach ($scorearr as $perio){
										$detail .= '<tr>
														<td>'.$perio->points.'</td>
														<td>'.seitcm_get_skill_name($perio->skill).'</td>
														<td>'.seitcm_create_date_from_mysql($perio->time).'</td>
													</tr>';
										$total_periodic += $perio->points;
									}
									$detail .= '</table></div>';
									$average_periodic = count($scorearr)==0 ? '-1' : round($total_periodic/count($scorearr),2);
									echo '<strong class="seitcm_click_detail" id="call_periodicpreviews_detail_'.$seitcm_row->id.'">'. ($average_periodic == '-1' ? '' : $average_periodic) .'</strong>';
									?>
									<div title="Detail periodic peviews score for <?php echo get_user_meta($seitcm_row->id, 'first_name', true)?>"
		    							id="periodicpreviews_detail_<?php echo $seitcm_row->id?>">
										<?php echo $detail;?>
									</div>
									<script type="text/javascript">
			    						$(document).ready(function() {
			    							$( "#periodicpreviews_detail_<?php echo $seitcm_row->id?>" ).dialog({
			    							      autoOpen: false,
			    							      modal: true,
			    							      width: 400,
			    							      show: {
			    							          effect: "blind",
			    							          duration: 100
			    							        },
			    							        hide: {
			    							          effect: "blind",
			    							          duration: 100
			    							        }
			    							    });
	
			    							$("#call_periodicpreviews_detail_<?php echo $seitcm_row->id?>").click(function() {
			    							      $( "#periodicpreviews_detail_<?php echo $seitcm_row->id?>" ).dialog( "open" );
			    							    });
		    							});
		    						</script>
								</td>
								<td>
									<?php 
									$detail = '<div style="height:200px; overflow-y:scroll; border: 1px #cfcfcf solid;border-radius: 5px 5px 0px 0px;margin-top: 5px;"><table class="seitcm_grid">
													<tr>
														<th>'.__('Result','SEITCM').'</th>
														<th colspan="4">'.__('Detail','SEITCM').'</th>
													</tr>';
									$scorearr = seitcm_get_list_examinationscores($seitcm_row->id, $seitcm_student_id);
									echo '<strong class="seitcm_click_detail" id="call_examinationscores_detail_'.$seitcm_row->id.'">';
									$total_exam_result = 0;
									$count_exam_result = 0;
									foreach ($scorearr as $exam){
										$total_exam = $exam->skill1 == '-1' ? 0 : $exam->skill1;
										$total_exam += $exam->skill2 == '-1' ? 0 : $exam->skill2;
										$total_exam += $exam->skill3 == '-1' ? 0 : $exam->skill3;
										$total_exam += $exam->skill4 == '-1' ? 0 : $exam->skill4;
										$count = $exam->skill1 == '-1' ? 0 : 1;
										$count += $exam->skill2 == '-1' ? 0 : 1;
										$count += $exam->skill3 == '-1' ? 0 : 1;
										$count += $exam->skill4 == '-1' ? 0 : 1;
										$total_exam_result += $count ==0 ? 0 : round($total_exam/$count,2,true);
										$count_exam_result += $count ==0? 0 : 1;
										$result = $count ==0? ' ' : round($total_exam/$count,2,true).' ';
										$skill1 = $exam->skill1 == '-1' ? '' : $exam->skill1;
										$skill2 = $exam->skill2 == '-1' ? '' : $exam->skill2;
										$skill3 = $exam->skill3 == '-1' ? '' : $exam->skill3;
										$skill4 = $exam->skill4 == '-1' ? '' : $exam->skill4;
										$str_row= '<tr>
														<td rowspan="2" style="text-align:center">
															<span style="font-size:18px; line-height:25px; color:#EE1D24;">'.$result.'</span><br />
															<span style="font-size:12px;">'.seitcm_create_date_from_mysql($exam->time).'</span>
														</td>
														<td>'.seitcm_get_skill_name(1).'</td>
														<td>'.seitcm_get_skill_name(2).'</td>
														<td>'.seitcm_get_skill_name(3).'</td>
														<td>'.seitcm_get_skill_name(4).'</td>
													<tr>
														<td>'.$skill1.'</td>
														<td>'.$skill2.'</td>
														<td>'.$skill3.'</td>
														<td>'.$skill4.'</td>
													</tr><tr style="height:1px;"><td colspan="5" style="height:1px; border-top:2px solid #999;"></td></tr>';
										$detail .= $str_row;
									}
									$average_exam = $count_exam_result==0? '-1' : $total_exam_result/$count_exam_result;
									echo $average_exam == '-1'? '' : $average_exam;
									echo '</strong>';
									$detail .= '</table></div>';
									?>
									<div title="Detail examination scores for <?php echo get_user_meta($seitcm_student_id, 'first_name', true)?>"
		    							id="examinationscores_detail_<?php echo $seitcm_row->id?>">
										<?php echo $detail;?>
									</div>
									<script type="text/javascript">
			    						$(document).ready(function() {
			    							$( "#examinationscores_detail_<?php echo $seitcm_row->id?>" ).dialog({
			    							      autoOpen: false,
			    							      modal: true,
			    							      width: 550,
			    							      show: {
			    							          effect: "blind",
			    							          duration: 100
			    							        },
			    							        hide: {
			    							          effect: "blind",
			    							          duration: 100
			    							        }
			    							    });
	
			    							$("#call_examinationscores_detail_<?php echo $seitcm_row->id?>").click(function() {
			    							      $( "#examinationscores_detail_<?php echo $seitcm_row->id?>" ).dialog( "open" );
			    							    });
		    							});
		    						</script>
								</td>
								<td>
								<strong style="color:#f00">
								<?php
									if($average_periodic!='-1'&&$average_exam!='-1')
									{
										global $seitcm_coefficient;
										echo $average = round((($average_exam*$seitcm_coefficient['exam']) + ($average_periodic*$seitcm_coefficient['periodic'])),2,true);
										$chartitem = array(
												'class' => $seitcm_row->codename . '.' . $seitcm_row->classcode,
												'result' => $average);
										
										array_push($chartdata, $chartitem);
									}
									else {
										if($average_periodic=='-1' && $average_exam!='-1') {
											echo $average_exam;
											$chartitem = array(
													'class' => $seitcm_row->codename . '.' . $seitcm_row->classcode,
													'result' => $average_exam);
											
											array_push($chartdata, $chartitem);
										}
										else if($average_exam=='-1' && $average_periodic!='-1') {
											echo $average_periodic;
											$chartitem = array(
													'class' => $seitcm_row->codename . '.' . $seitcm_row->classcode,
													'result' => $average_periodic);
												
											array_push($chartdata, $chartitem);
										}
										else 
										{
										}
									}
									
								?>
								</strong>
								</td>
							</tr>
							<?php
						}
						?>
				</tbody></table>
			</div>
		</div>
		<div class="seitcm_bigwidget_block">
			<div class="seitcm_bigwidget_block_inner">
				<h3><?php _e('Statitic chart')?></h3>
				<?php require_once 'seitcm_chart_student_learning.php';?>
			</div>
		</div>
	</div>